package git.determinal.template.view;





import java.util.Arrays;

public enum MatchType {
    EQ("=", "EQ", "等于"),
    NE("<>", "NE", "不等于 "),
    GT(">", "GT", "大于"),
    GE(">=", "GE", "大等于"),
    LT("<", "LT", "小于"),
    LE("<=", "LE", "小等于"),
    LIKE("LIKE", "LIKE", "LIKE"),
    NOT_LIKE("NOT LIKE", "NOTLIKE", "NOT LIKE"),
    LEFT_LIKE("LEFT LIKE", "LEFTLIKE", "LEFT LIKE"),
    RIGHT_LIKE("RIGHT LIKE", "RIGHTLIKE", "RIGHT LIKE"),
    IS_NULL("IS NULL", "ISNULL", "为空"),
    IS_NOT_NULL("IS NOT NULL", "ISNOTNULL", "不为空"),
    IN("IN", "IN", "包含"),
    NOT_IN("NOT IN", "NOTIN", "不包含"),
    BETWEEN("BETWEEN", "BETWEEN", "存在范围内"),
    NOT_BETWEEN("NOT BETWEEN", "NOTBETWEEN", "不存在范围内"),
    RANGE("RANGE", "RANGE", "存在范围内");

    private String value;
    private String alias;
    private String label;

    public String getValue() {
        return this.value;
    }

    public void setValue(String value) {
        this.value = value;
    }

    public String getAlias() {
        return this.alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getLabel() {
        return this.label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    private MatchType(String value, String alias, String label) {
        this.value = value;
        this.alias = alias;
        this.label = label;
    }

    public boolean equal(MatchType matchType) {
        return this.value.toUpperCase().equals(matchType.getValue().toUpperCase()) || this.alias.toUpperCase().equals(matchType.getAlias().toUpperCase());
    }

    public static MatchType load(String value) {
        return value != null && !"".equals(value) ? (MatchType)Arrays.stream(values()).filter((enumObj) -> {
            return enumObj.getValue().toUpperCase().equals(value.toUpperCase()) || enumObj.getAlias().toUpperCase().equals(value.toUpperCase());
        }).findFirst().get() : EQ;
    }
}

